<template>
  <div class="swiper">
    <swiper
      :slidesPerView="1"
      :autoplay="{ delay: 1000, disableOnInteraction: false }"
      :navigation="true"
      :pagination="{ type: 'bullets', clickable: true }"
      :scrollbar="{ draggable: false }"
      :space-between="0"
      :modules="modules"
      :loop="true"
      @mouseenter="enter"
      @mouseleave="leave"
      @swiper="onSwiper"
      @slideChange="onSlideChange"
      direction="vertical"
    >
      <swiper-slide
        @click="newDetilsFN(item)"
        v-for="(item, index) in footSwiperData"
        :key="index"
        class="swiperItem"
      >
        <div class="imgeBox center">
          <img
            :src="$t(`messages.news.footSwiperList[${index}].image`)"
            alt=""
            srcset=""
            v-if="item.fileType == 'image'"
          />
          <video class="video" v-else autoplay loop>
            <source :src="$t(`messages.news.footSwiperList[${index}].image`)" type="video/mp4" />
          </video>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script setup>
import { useI18n } from "vue-i18n"
import { newFootSlideshow } from '@/http/api/news.js'
import Zh from '@/assets/i18n/langs/zh.js'
import En from '@/assets/i18n/langs/en.js'
import { toRaw, ref, reactive, onMounted } from 'vue'
import { Swiper, SwiperSlide } from 'swiper/vue'
import 'swiper/css'
import 'swiper/scss/navigation'
import 'swiper/scss/pagination'
import { Autoplay, Navigation, Scrollbar, A11y } from 'swiper/modules'
const props = defineProps()

let modules = [Autoplay, Navigation, Scrollbar, A11y]
//定义swiperNew,目的获取非响应式swiper
let swiperNew = ''

//鼠标移入
const enter = () => {
  swiperNew.autoplay.stop()
}
//鼠标移出
const leave = () => {
  swiperNew.autoplay.start()
}
const onSwiper = (swiper) => {
  // console.log(swiper);

  swiperNew = toRaw(swiper) //拿到swiper对象再转换为非响应式
}
const onSlideChange = () => {
  // console.log("slide change");
}

let typeAll = {
  image: ['png', 'jpg', 'jpeg', 'svg'],
  video: ['avi', 'mpeg', 'mp4', 'wmv', 'flv', 'mov', 'mkv', 'rmvb', '3gp']
}
let swiperData = ref([])
let pageData = reactive({
  page: 1,
  size: 50
})
let footSwiperData = ref([])
const footList = async () => {
  let res = await newFootSlideshow(pageData)
  Zh.messages.news.footSwiperList = res.res.map((item) => {
    return {
      title: item.title,
      image: item.image
    }
  })
  En.messages.news.footSwiperList = res.res.map((item) => {
    return {
      title: item.title,
      image: item.image
    }
  })

  footSwiperData.value = res.res.map((item) => {
    let type = item.image.split('.')[item.image.split('.').length - 1]
    let size = ''
    for (const key in typeAll) {
      typeAll[key].forEach((item1) => {
        if (item1 == type) {
          size = key
        }
      })
    }
    return {
      ...item,
      fileType: size
    }
  })
}
onMounted(() => {
  footList()
})
</script>
<style lang="scss" scoped>
.swiper {
  width: 100% !important;
  height: 100%;
  margin: 0;
  img {
    width: 100%;
    height: 100%;
  }
}
.swiperItem {
  height: 820px !important;
  .imgeBox {
    width: 100%;
    height: 100%;
    img {
      width: 1450px;
      height: 680px;
    }
  }
}
::v-deep(.swiper-pagination-bullet) {
  //修改分页器圆点大小
  width: 8px;
  height: 8px;
  background-color: #fff;
}

.swiper-horizontal > .swiper-pagination-bullets .swiper-pagination-bullet,
::v-deep(.swiper-pagination-horizontal.swiper-pagination-bullets) .swiper-pagination-bullet {
  // 分页器远点之间的距离
  margin: 0 10px;
}

::v-deep(.swiper-button-prev),
::v-deep(.swiper-button-next) {
  color: black;
  width: 70px;
  height: 70px;
  background: #ffffff;
  border-radius: 35px;
}
</style>

